package com.kx.smsolatform.mq;

import com.kx.smsolatform.service.SearcherService;
import com.kx.smsplatform.common.constants.RabbitMQConstants;
import com.kx.smsplatform.common.model.StandardReport;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;

import java.io.IOException;

/**
 * 监听消息队列，进行更新日志操作
 * @Author Sun
 * @Date 2021/7/6 17:39
 */
@Slf4j
@Configuration
public class UpdateListener {
    @Autowired
    private SearcherService searcherService;

    @RabbitListener(queues = {RabbitMQConstants.TOPIC_UPDATE_SMS_REPORT})
    public void consume(StandardReport report, Channel channel, Message message) throws IOException {
        log.info("【搜索模块：更新日志】已接收到队列：{} 的消息：report={}",RabbitMQConstants.TOPIC_UPDATE_SMS_REPORT,report);
        //更新es中的日志信息
        searcherService.updateLog(report);
        //手动ACK
        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
    }
}
